﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Demo
{
    class ForeachStatisticalString
    {
        public static void Demo1()
        { 
            Console.WriteLine("请输入一个字符串");
            string str = Console.ReadLine();

            int letterCount = 0;
            int numCount = 0;
            int spaceCount = 0;

            foreach(var a in str)
            {
                if(char.IsLetter(a))
                {
                    letterCount++;
                }
                else if(char.IsDigit(a))
                {
                    numCount++;
                }
                else if(char.IsWhiteSpace(a))
                {
                    spaceCount++;
                }
            }
            Console.WriteLine("您输入的字符串中,字母有{0}个,数字有{1}个,空格有{2}个",letterCount,numCount,spaceCount);
        }

    }
}
